package com.vito.oa.act.extend.action;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.act.model.ActExTableColsModel;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.oa.act.extend.model.OaActExTableColsModel;
import com.vito.oa.act.extend.service.OaActExTableColsService;
@Controller
@RequestMapping("oa/act/actExTableCols")
public class OaActExTableColsAction extends BaseAction{
	
	private static final Logger log = LoggerFactory.getLogger(OaActExTableColsAction.class);
	
	@Reference(group="OaActExTableColsServiceImpl")
	private OaActExTableColsService actExTableColsService;
	
	@RequestMapping("queryActExTableCols")
	@ResponseBody
	public Result queryActExTableCols(OaActExTableColsModel actExTableModel){
		Result rs = new Result();
		try{
			rs.setData(actExTableColsService.queryOaActExTableColsByPage(actExTableModel));
			rs.setCode(Result.CODE_OK);
		}catch(Exception e){
			log.error("查询异常：",e);
			rs.setCode(Result.CODE_ERROR);
		}
		return rs;
	}
	@RequestMapping("saveActExTableCols")
	@ResponseBody
	public Result saveActExTableCols(OaActExTableColsModel actExTableModel){
		Result rs = new Result();
		try{
			List<OaActExTableColsModel> list = actExTableColsService.queryOaActExTableCols(actExTableModel);
			if(list != null && list.size()>0){
				rs.setCode(Result.CODE_PARA_ERROR);
				rs.setMsg("表字段名重复！");
				return rs;
			}
			int count = actExTableColsService.saveActExTableCols(actExTableModel);
			if(count>0){
				rs.setCode(Result.CODE_OK);
				rs.setMsg(ResMsg.SAVESUC);
			}else{
				rs.setCode(Result.CODE_OK);
				rs.setMsg(ResMsg.SAVEERR);
			}
		}catch(Exception e){
			log.error("保存异常：",e);
			rs.setCode(Result.CODE_ERROR);
		}
		return rs;
	}
	@RequestMapping("updateActExTableCols")
	@ResponseBody
	public Result updateActExTableCols(OaActExTableColsModel actExTableModel){
		Result rs = new Result();
		try{
			List<OaActExTableColsModel> list = actExTableColsService.queryOaActExTableCols(actExTableModel);
			if(list != null && list.size()>0){
				if(!actExTableModel.getColKey().equals(list.get(0).getColKey())){
					rs.setCode(Result.CODE_PARA_ERROR);
					rs.setMsg("表字段名重复！");
					return rs;
				}
			}
			int count = actExTableColsService.updateActExTableCols(actExTableModel);
			if(count>0){
				rs.setCode(Result.CODE_OK);
				rs.setMsg(ResMsg.UPDSUC);
			}else{
				rs.setCode(Result.CODE_OK);
				rs.setMsg(ResMsg.UPDERR);
			}
		}catch(Exception e){
			log.error("更新异常：",e);
			rs.setCode(Result.CODE_ERROR);
		}
		return rs;
	}
	@RequestMapping("deleteActExTableCols")
	@ResponseBody
	public Result deleteActExTableCols(ActExTableColsModel actExTableModel){
		Result rs = new Result();
		try{
			int count = actExTableColsService.deleteActExTableCols(actExTableModel);
			if(count>0){
				rs.setCode(Result.CODE_OK);
				rs.setMsg(ResMsg.DELSUC);
			}else{
				rs.setCode(Result.CODE_OK);
				rs.setMsg(ResMsg.DELERR);
			}
		}catch(Exception e){
			log.error("删除异常：",e);
			rs.setCode(Result.CODE_ERROR);
		}
		return rs;
	}
}
